package com.ding.easycontroller.config;

import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;

import javax.script.*;

@Configuration
public class ScriptConfig {

    @Bean
    public ScriptContext globalContext() {
        return new SimpleScriptContext();
    }

    @Bean
    public ScriptEngine scriptEngine(ScriptContext scriptContext) throws ScriptException {
        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
        engine.setContext(scriptContext);
        return engine;
    }


    @Bean
    public XMLOutputter xmlOutputter() {
        Format format = Format.getPrettyFormat();
        format.setIndent("    ");
        format.setEncoding("utf-8");
        return new XMLOutputter(format);
    }


}
